﻿#ifndef JSONVIWER_H
#define JSONVIWER_H

#include <QMainWindow>
#include <QLabel>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QTreeWidget>
#include "saveproject.h"

namespace Ui {
class JsonViwer;
}

class JsonViwer : public QMainWindow
{
    Q_OBJECT

public:
    explicit JsonViwer(QWidget *parent = 0);
    ~JsonViwer();

public slots:
    void newProject(const QString &filePath);
    void chooseProject(const QString &filePath);

private slots:
    void on_actionFormat_triggered();

    void on_actionClearFormat_triggered();

    void on_tabWidget_tabCloseRequested(int index);

    void on_actionNewProject_triggered();

    void on_actionNewDoc_triggered();

    void on_actionSave_triggered();

    void on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);

    void on_actionOpenDoc_triggered();

private:
    QJsonArray readConfigFile(const QString &fileName);
    void saveConfigFile(const QString &fileName, const QJsonArray &config);

    void loadConfig(const QJsonArray &config);

    void switchDocumentPage(const QString filePath);

private:
    Ui::JsonViwer *ui;
    SaveProject *m_chooseProj;

    QString m_configFileName;

    // data
    QJsonArray m_config;
};

#endif // JSONVIWER_H
